package com.zheng.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.zheng.mall.dao.PmsProductAttributeCategoryDao;
import com.zheng.mall.dto.PmsProductAttributeCategoryItem;
import com.zheng.mall.mapper.PmsProductAttributeCategoryMapper;
import com.zheng.mall.model.PmsProductAttributeCategory;
import com.zheng.mall.model.PmsProductAttributeCategoryExample;
import com.zheng.mall.service.PmsProductAttributeCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品属性分类Service
 * @author zheng
 */
@Service
public class PmsProductAttributeCategoryServiceImpl implements PmsProductAttributeCategoryService {
    @Autowired
    private PmsProductAttributeCategoryMapper pmsProductAttributeCategoryMapper;
    @Autowired
    private PmsProductAttributeCategoryDao pmsProductAttributeCategoryDao;
    /**
     * 创建属性分类
     *
     * @param name
     */
    @Override
    public int create(String name) {
        PmsProductAttributeCategory productAttributeCategory = new PmsProductAttributeCategory();
        productAttributeCategory.setName(name);
        return pmsProductAttributeCategoryMapper.insertSelective(productAttributeCategory);
    }

    /**
     * 修改属性分类
     *
     * @param id
     * @param name
     */
    @Override
    public int update(Long id, String name) {
        PmsProductAttributeCategory productAttributeCategory = new PmsProductAttributeCategory();
        productAttributeCategory.setName(name);
        productAttributeCategory.setId(id);
        return pmsProductAttributeCategoryMapper.updateByPrimaryKeySelective(productAttributeCategory);
    }

    /**
     * 删除属性分类
     *
     * @param id
     */
    @Override
    public int delete(Long id) {
        return pmsProductAttributeCategoryMapper.deleteByPrimaryKey(id);
    }

    /**
     * 获取属性分类详情
     *
     * @param id
     */
    @Override
    public PmsProductAttributeCategory getItem(Long id) {
        return pmsProductAttributeCategoryMapper.selectByPrimaryKey(id);
    }

    /**
     * 分页查询属性分类
     *
     * @param pageSize
     * @param pageNum
     */
    @Override
    public List<PmsProductAttributeCategory> getList(Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        return pmsProductAttributeCategoryMapper.selectByExample(new PmsProductAttributeCategoryExample());
    }

    /**
     * 获取包含属性的属性分类
     */
    @Override
    public List<PmsProductAttributeCategoryItem> getListWithAttr() {
        return pmsProductAttributeCategoryDao.getListWithAttr();
    }
}
